<template>
	<view>
		<uni-section class="pub-title" title="客户信息" type="line"></uni-section>
		<uni-card :isShadow="true">
			<uni-forms-item label="车牌号" name="">
				<uni-easyinput type="text" v-model="clientInfo.bebxcph" placeholder=""
					:inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="车型" name="">
				<uni-easyinput type="textarea" v-model="clientInfo.chelmc" placeholder=""
					:inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="姓名" name="">
				<uni-easyinput type="text" v-model="clientInfo.beibxr" placeholder=""
					:inputBorder="true" disabled="true" />
			</uni-forms-item>
			<uni-forms-item label="电话" name="">
				<uni-easyinput type="text" v-model="clientInfo.beibxrlxdh" placeholder=""
					:inputBorder="true" disabled="true" />
			</uni-forms-item>
		</uni-card>
		
		<uni-card :isShadow="true">
			<uni-section class="pub-title" title="可用优惠劵" type="line"></uni-section>
			<uni-list v-for="(item ,index) in youhjlb" :key="index">
			    <uni-list-item :title="item.youhjmingc" :thumb="item.youhjtup"
			     thumb-size="lg" :rightText="item.fafsl" clickable @click="onClick(item)" link=""></uni-list-item>
			</uni-list>
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				clientInfo: {},
				youhjlb: [],
			}
		},

		onLoad() {
			let that = this

			uni.scanCode({
				onlyFromCamera: true,
				success: function(res) {
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
					that.getClientInfo(res.result)
					that.keyyhjlb(res.result)

				}
			});
			
			
			
		},

		methods: {
			keyyhjlb(kehsjh) {
				let that = this
				
				uni.request({
					url: getApp().globalData.serviceUrl + "/youhjfaf/kuybYouhjFaf/wodyhjlb",
					data: {
						kehsjh: kehsjh
					},
					header: {
						"X-Access-Token": uni.getStorageSync("token")
					},
					dataType: 'json',
					method: 'GET',
					success: (result) => {
						if (result.data.success) {
							that.youhjlb = result.data.result
						}
					}
				})
			},
			
			onClick(youhj) {
				let that = this
				
				uni.showModal({
				    title: '提示',
				    content: '确认核销么?',
				    success: function (res) {
				        if (res.confirm) {
				            console.log('用户点击确定');
							
							// {"youhj":"1482119919362990082","keh":"18646012726","kehdh":"1","cheph":"2","hexjg":"1453175536997748738","hexr":"18646012726","hexshl":"1"}
							
							uni.request({
								url: getApp().globalData.serviceUrl + "/youhjhex/kuybYouhjHex/add",
								data: {
									fafid: youhj.id,
									youhj: youhj.youhj,
									keh: that.clientInfo.beibxrlxdh,
									kehdh: that.clientInfo.beibxrlxdh,
									cheph: that.clientInfo.bebxcph,
									hexshl: 1
								},
								header: {
									"X-Access-Token": uni.getStorageSync("token")
								},
								dataType: 'json',
								method: 'POST',
								success: (result) => {
									if (result.data.success) {
										uni.showToast({
											title: '核销成功!',
											icon: 'none'
										})
										
										that.keyyhjlb(that.clientInfo.beibxrlxdh)
										
									} else {
										uni.showToast({
											title: result.data.message,
											icon: 'none'
										})
									}
									
								}
							})
							
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			
			getClientInfo(kehsjh) {
				let that = this
				
				uni.request({
					url: getApp().globalData.serviceUrl + "/youhjfaf/kuybYouhjFaf/getClientInfo",
					data: {
						kehsjh: kehsjh
					},
					header: {
						"X-Access-Token": uni.getStorageSync("token")
					},
					dataType: 'json',
					method: 'GET',
					success: (result) => {
						if (result.data.success) {
							that.clientInfo = result.data.result
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>
